

<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>Urban Computing ToolBox &mdash; UCTB  documentation</title>
  

  
  

  

  
  
    

  

  
  
    <link rel="stylesheet" href="../_static/css/theme.css" type="text/css" />
  

  

  
        <link rel="index" title="Index"
              href="../genindex.html"/>
        <link rel="search" title="Search" href="../search.html"/>
    <link rel="top" title="UCTB  documentation" href="../index.html"/> 

  
  <script src="../_static/js/modernizr.min.js"></script>

</head>

<body class="wy-body-for-nav" role="document">

   
  <div class="wy-grid-for-nav">

    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search">
          

          
            <a href="../index.html" class="icon icon-home"> UCTB
          

          
          </a>

          
            
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
                <ul>
<li class="toctree-l1"><a class="reference internal" href="introduction.html">1. Introduction</a></li>
<li class="toctree-l1"><a class="reference internal" href="installation.html">2. Installation</a></li>
<li class="toctree-l1"><a class="reference internal" href="quickstart.html">3. Quick start</a></li>
<li class="toctree-l1"><a class="reference internal" href="tutorial.html">4. Tutorial</a></li>
<li class="toctree-l1"><a class="reference internal" href="../APIReference.html">5. API Reference</a></li>
<li class="toctree-l1"><a class="reference internal" href="all_results.html">6. Results on different datasets</a></li>
<li class="toctree-l1"><a class="reference internal" href="uctb_group.html">7. About us (UCTB Group)</a></li>
</ul>

            
          
        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" role="navigation" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../index.html">UCTB</a>
        
      </nav>


      
      <div class="wy-nav-content">
        <div class="rst-content">
          













<div role="navigation" aria-label="breadcrumbs navigation">
  <ul class="wy-breadcrumbs">
    
      <li><a href="../index.html">Docs</a> &raquo;</li>
        
      <li>Urban Computing ToolBox</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
            
            <a href="../_sources/md_file/index.md.txt" rel="nofollow"> View page source</a>
          
        
      </li>
    
  </ul>
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <div class="section" id="urban-computing-toolbox">
<h1><a class="reference external" href="https://github.com/Di-Chai/UCTB">Urban Computing ToolBox</a><a class="headerlink" href="#urban-computing-toolbox" title="Permalink to this headline">¶</a></h1>
<div class="section" id="introduction">
<h2>Introduction<a class="headerlink" href="#introduction" title="Permalink to this headline">¶</a></h2>
<p><strong>Urban Computing ToolBox</strong> is a package providing spatial-temporal predicting models. It contains both conventional models and state-of-art models.</p>
<p>Currently the package supported the following models: (<a class="reference external" href="./static/current_supported_models.html">Details</a>)</p>
<ul class="simple">
<li><p>ARIMA</p></li>
<li><p>DCRNN</p></li>
<li><p>DeepST</p></li>
<li><p>GeoMAN</p></li>
<li><p>HM</p></li>
<li><p>HMM</p></li>
<li><p>ST-MGCN</p></li>
<li><p>ST-ResNet</p></li>
<li><p>STMeta</p></li>
<li><p>XGBoost</p></li>
</ul>
<p>UCTB is a flexible and open package. You can use the data we provided or use your own data, the data structure is well stated in the tutorial chapter. You can build your own model based on model-units we provided and use the model-training class to train the model.</p>
</div>
<div class="section" id="installation">
<h2>Installation<a class="headerlink" href="#installation" title="Permalink to this headline">¶</a></h2>
<div class="section" id="install-uctb">
<h3>Install UCTB<a class="headerlink" href="#install-uctb" title="Permalink to this headline">¶</a></h3>
<div class="section" id="step-1-install-tensorflow">
<h4>Step 1: Install TensorFlow<a class="headerlink" href="#step-1-install-tensorflow" title="Permalink to this headline">¶</a></h4>
<p>You can skip to step 2 if you already installed tensorflow.</p>
<p>You can refer to this page <a class="reference external" href="https://www.tensorflow.org/install">https://www.tensorflow.org/install</a> to install tensorflow, if you have a Nvidia GPU installed on you computer, we highly recommend you to install GPU version of tensorflow.</p>
</div>
<div class="section" id="step-2-install-uctb">
<h4>Step 2: Install UCTB<a class="headerlink" href="#step-2-install-uctb" title="Permalink to this headline">¶</a></h4>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>pip install --upgrade UCTB
</pre></div>
</div>
<p>The following required package will be installed or upgraded with UCTB:</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span><span class="s1">&#39;hmmlearn&#39;</span>,
<span class="s1">&#39;keras&#39;</span>,
<span class="s1">&#39;GPUtil&#39;</span>,
<span class="s1">&#39;numpy&#39;</span>,
<span class="s1">&#39;pandas&#39;</span>,
<span class="s1">&#39;python-dateutil&#39;</span>,
<span class="s1">&#39;scikit-learn&#39;</span>,
<span class="s1">&#39;scipy&#39;</span>,
<span class="s1">&#39;statsmodels&#39;</span>,
<span class="s1">&#39;wget&#39;</span>,
<span class="s1">&#39;xgboost&#39;</span>,
<span class="s1">&#39;nni&#39;</span>,
<span class="s1">&#39;chinesecalendar&#39;</span>,
<span class="s1">&#39;PyYAML&#39;</span>
</pre></div>
</div>
</div>
</div>
<div class="section" id="uctb-docker">
<h3>UCTB Docker<a class="headerlink" href="#uctb-docker" title="Permalink to this headline">¶</a></h3>
<p>You can also  use UCTB by docker. First pull uctb docker from docker hub.</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>docker pull dichai/uctb:v0.2.0
</pre></div>
</div>
<p>And  you then can run it.</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>docker run  --runtime<span class="o">=</span>nvidia  -it -d dichai/uctb:v0.2.0 /bin/bash
</pre></div>
</div>
</div>
</div>
<div class="section" id="quick-start">
<h2>Quick start<a class="headerlink" href="#quick-start" title="Permalink to this headline">¶</a></h2>
<ul class="simple">
<li></li>
</ul>
<div class="section" id="quick-start-with-stmeta">
<h3>Quick start with STMeta<a class="headerlink" href="#quick-start-with-stmeta" title="Permalink to this headline">¶</a></h3>
</div>
</div>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">UCTB.dataset</span> <span class="kn">import</span> <span class="n">NodeTrafficLoader</span>
<span class="kn">from</span> <span class="nn">UCTB.model</span> <span class="kn">import</span> <span class="n">STMeta</span>
<span class="kn">from</span> <span class="nn">UCTB.evaluation</span> <span class="kn">import</span> <span class="n">metric</span>

<span class="c1"># Config data loader</span>
<span class="n">data_loader</span> <span class="o">=</span> <span class="n">NodeTrafficLoader</span><span class="p">(</span><span class="n">dataset</span><span class="o">=</span><span class="s1">&#39;Bike&#39;</span><span class="p">,</span> <span class="n">city</span><span class="o">=</span><span class="s1">&#39;NYC&#39;</span><span class="p">,</span> <span class="n">graph</span><span class="o">=</span><span class="s1">&#39;Correlation&#39;</span><span class="p">,</span>
                                <span class="n">closeness_len</span><span class="o">=</span><span class="mi">6</span><span class="p">,</span> <span class="n">period_len</span><span class="o">=</span><span class="mi">7</span><span class="p">,</span> <span class="n">trend_len</span><span class="o">=</span><span class="mi">4</span><span class="p">,</span> <span class="n">normalize</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>

<span class="c1"># Init model object</span>
<span class="n">STMeta_Obj</span> <span class="o">=</span> <span class="n">STMeta</span><span class="p">(</span><span class="n">closeness_len</span><span class="o">=</span><span class="n">data_loader</span><span class="o">.</span><span class="n">closeness_len</span><span class="p">,</span>
                                 <span class="n">period_len</span><span class="o">=</span><span class="n">data_loader</span><span class="o">.</span><span class="n">period_len</span><span class="p">,</span>
                                 <span class="n">trend_len</span><span class="o">=</span><span class="n">data_loader</span><span class="o">.</span><span class="n">trend_len</span><span class="p">,</span>
                                 <span class="n">num_node</span><span class="o">=</span><span class="n">data_loader</span><span class="o">.</span><span class="n">station_number</span><span class="p">,</span>
                                 <span class="n">num_graph</span><span class="o">=</span><span class="n">data_loader</span><span class="o">.</span><span class="n">LM</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>

<span class="c1"># Build tf-graph</span>
<span class="n">STMeta_Obj</span><span class="o">.</span><span class="n">build</span><span class="p">()</span>
<span class="c1"># Training</span>
<span class="n">STMeta_Obj</span><span class="o">.</span><span class="n">fit</span><span class="p">(</span><span class="n">closeness_feature</span><span class="o">=</span><span class="n">data_loader</span><span class="o">.</span><span class="n">train_closeness</span><span class="p">,</span>
                      <span class="n">period_feature</span><span class="o">=</span><span class="n">data_loader</span><span class="o">.</span><span class="n">train_period</span><span class="p">,</span>
                      <span class="n">trend_feature</span><span class="o">=</span><span class="n">data_loader</span><span class="o">.</span><span class="n">train_trend</span><span class="p">,</span>
                      <span class="n">laplace_matrix</span><span class="o">=</span><span class="n">data_loader</span><span class="o">.</span><span class="n">LM</span><span class="p">,</span>
                      <span class="n">target</span><span class="o">=</span><span class="n">data_loader</span><span class="o">.</span><span class="n">train_y</span><span class="p">,</span>
                      <span class="n">sequence_length</span><span class="o">=</span><span class="n">data_loader</span><span class="o">.</span><span class="n">train_sequence_len</span><span class="p">)</span>

<span class="c1"># Predict</span>
<span class="n">prediction</span> <span class="o">=</span> <span class="n">STMeta_Obj</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">closeness_feature</span><span class="o">=</span><span class="n">data_loader</span><span class="o">.</span><span class="n">test_closeness</span><span class="p">,</span>
                                       <span class="n">period_feature</span><span class="o">=</span><span class="n">data_loader</span><span class="o">.</span><span class="n">test_period</span><span class="p">,</span>
                                       <span class="n">trend_feature</span><span class="o">=</span><span class="n">data_loader</span><span class="o">.</span><span class="n">test_trend</span><span class="p">,</span>
                                       <span class="n">laplace_matrix</span><span class="o">=</span><span class="n">data_loader</span><span class="o">.</span><span class="n">LM</span><span class="p">,</span>
                                       <span class="n">target</span><span class="o">=</span><span class="n">data_loader</span><span class="o">.</span><span class="n">test_y</span><span class="p">,</span>
                                       <span class="n">output_names</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;prediction&#39;</span><span class="p">],</span>
                                       <span class="n">sequence_length</span><span class="o">=</span><span class="n">data_loader</span><span class="o">.</span><span class="n">test_sequence_len</span><span class="p">)</span>

<span class="c1"># Evaluate</span>
<span class="nb">print</span><span class="p">(</span><span class="s1">&#39;Test result&#39;</span><span class="p">,</span> <span class="n">metric</span><span class="o">.</span><span class="n">rmse</span><span class="p">(</span><span class="n">prediction</span><span class="o">=</span><span class="n">data_loader</span><span class="o">.</span><span class="n">normalizer</span><span class="o">.</span><span class="n">min_max_denormal</span><span class="p">(</span><span class="n">prediction</span><span class="p">[</span><span class="s1">&#39;prediction&#39;</span><span class="p">]),</span>
                                 <span class="n">target</span><span class="o">=</span><span class="n">data_loader</span><span class="o">.</span><span class="n">normalizer</span><span class="o">.</span><span class="n">min_max_denormal</span><span class="p">(</span><span class="n">data_loader</span><span class="o">.</span><span class="n">test_y</span><span class="p">),</span> <span class="n">threshold</span><span class="o">=</span><span class="mi">0</span><span class="p">))</span>
</pre></div>
</div>
<ul class="simple">
<li><p><a class="reference external" href="./static/quick_start.html">Quick start with other models</a></p></li>
</ul>
<div class="section" id="tutorial">
<h2>Tutorial<a class="headerlink" href="#tutorial" title="Permalink to this headline">¶</a></h2>
<ul class="simple">
<li><p>Compare different version of STMeta</p></li>
<li></li>
</ul>
<div class="section" id="use-datasets-from-uctb">
<h3><a class="reference external" href="./static/tutorial.html">Use datasets from UCTB</a><a class="headerlink" href="#use-datasets-from-uctb" title="Permalink to this headline">¶</a></h3>
</div>
<li></li>
<div class="section" id="build-your-own-datasets">
<h3><a class="reference external" href="./static/tutorial.html">Build your own datasets</a><a class="headerlink" href="#build-your-own-datasets" title="Permalink to this headline">¶</a></h3>
</div>
<li></li>
<div class="section" id="use-build-in-models-from-uctb">
<h3>Use build-in models from UCTB<a class="headerlink" href="#use-build-in-models-from-uctb" title="Permalink to this headline">¶</a></h3>
</div>
<li></li>
<div class="section" id="build-your-own-model-using-uctb">
<h3>Build your own model using UCTB<a class="headerlink" href="#build-your-own-model-using-uctb" title="Permalink to this headline">¶</a></h3>
</div>
</div>
<div class="section" id="api-reference">
<h2>API Reference<a class="headerlink" href="#api-reference" title="Permalink to this headline">¶</a></h2>
<ul class="simple">
<li></li>
</ul>
<div class="section" id="model-class">
<h3>Model Class<a class="headerlink" href="#model-class" title="Permalink to this headline">¶</a></h3>
</div>
<li></li>
<div class="section" id="modelunit-class">
<h3>ModelUnit Class<a class="headerlink" href="#modelunit-class" title="Permalink to this headline">¶</a></h3>
</div>
<li></li>
<div class="section" id="evaluation-class">
<h3>Evaluation Class<a class="headerlink" href="#evaluation-class" title="Permalink to this headline">¶</a></h3>
</div>
<li></li>
<div class="section" id="training-class">
<h3>Training Class<a class="headerlink" href="#training-class" title="Permalink to this headline">¶</a></h3>
</div>
</div>
<div class="section" id="full-examples">
<h2>Full examples<a class="headerlink" href="#full-examples" title="Permalink to this headline">¶</a></h2>
<ul class="simple">
<li></li>
</ul>
<div class="section" id="experiments-on-bike-traffic-flow-prediction">
<h3><a class="reference external" href="./static/experiment_on_bike.html">Experiments on bike traffic-flow prediction</a><a class="headerlink" href="#experiments-on-bike-traffic-flow-prediction" title="Permalink to this headline">¶</a></h3>
</div>
<li></li>
<div class="section" id="experiments-on-metro-traffic-flow-prediction">
<h3><a class="reference external" href="./static/experiment_on_metro.html">Experiments on metro traffic-flow prediction</a><a class="headerlink" href="#experiments-on-metro-traffic-flow-prediction" title="Permalink to this headline">¶</a></h3>
</div>
<li></li>
<div class="section" id="experiments-on-didi-order-demand-prediction">
<h3><a class="reference external" href="./static/experiment_on_didi.html">Experiments on didi order demand prediction</a><a class="headerlink" href="#experiments-on-didi-order-demand-prediction" title="Permalink to this headline">¶</a></h3>
</div>
<li><p>Experiments on charge station demand prediction</p></li>
</div>
<div class="section" id="contribute-to-uctb-delay">
<h2>Contribute to UCTB (Delay)<a class="headerlink" href="#contribute-to-uctb-delay" title="Permalink to this headline">¶</a></h2>
<ul class="simple">
<li></li>
</ul>
<div class="section" id="contribute-data">
<h3>Contribute Data<a class="headerlink" href="#contribute-data" title="Permalink to this headline">¶</a></h3>
</div>
<li></li>
<div class="section" id="contribute-models">
<h3>Contribute Models<a class="headerlink" href="#contribute-models" title="Permalink to this headline">¶</a></h3>
</div>
<li></li>
<div class="section" id="contribute-model-units">
<h3>Contribute Model-Units<a class="headerlink" href="#contribute-model-units" title="Permalink to this headline">¶</a></h3>
</div>
</div>
</div>


           </div>
          </div>
          <footer>
  

  <hr/>

  <div role="contentinfo">
    <p>
        &copy; Copyright 2019, UCTB group.

    </p>
  </div>
  Built with <a href="http://sphinx-doc.org/">Sphinx</a>. 

</footer>

        </div>
      </div>

    </section>

  </div>
  


  

    <script type="text/javascript">
        var DOCUMENTATION_OPTIONS = {
            URL_ROOT:'../',
            VERSION:'',
            COLLAPSE_INDEX:false,
            FILE_SUFFIX:'.html',
            HAS_SOURCE: 'true'
        };
    </script>
      <script type="text/javascript" src="../_static/jquery.js"></script>
      <script type="text/javascript" src="../_static/underscore.js"></script>
      <script type="text/javascript" src="../_static/doctools.js"></script>
      <script type="text/javascript" src="../_static/language_data.js"></script>

  

  
  
    <script type="text/javascript" src="../_static/js/theme.js"></script>
  

  
  
  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.StickyNav.enable();
      });
  </script>
   

</body>
</html>